package io.renren.modules.workmanagement.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.workmanagement.constans.UserConstans;
import io.renren.modules.workmanagement.entity.CourseEntity;
import io.renren.modules.workmanagement.service.CourseService;
import io.renren.modules.workmanagement.vo.ClassCourse.CourseCourseVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 *
 *
 * @author yewei
 * @email sunlightcs@gmail.com
 * @date 2022-02-19 16:02:49
 */
@RestController
@RequestMapping("workmanagement/course")
public class CourseController extends AbstractController {
    @Autowired
    private CourseService courseService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("department:sys:list")
    public R list(@RequestParam Map<String, Object> params){
        Long userId = getUserId();
        params.put(UserConstans.USER_ID_KEY,userId);
        PageUtils page = courseService.queryPage(params);

        return R.ok().put("page", page);
    }
    /**
     * 列表
     */
    @GetMapping("/getMyCourse")
    public R getMyCourse(){
        List<CourseCourseVO> courseCourseVOS= courseService.getMyCourse(getUserId());

        return R.ok().put("courses", courseCourseVOS);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("department:sys:info")
    public R info(@PathVariable("id") Integer id){
		CourseEntity course = courseService.getById(id);

        return R.ok().put("course", course);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("department:sys:save")
    public R save(@RequestBody CourseEntity course){
        Long userId = getUserId();
		courseService.saveCourse(course,userId);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("department:sys:update")
    public R update(@RequestBody CourseEntity course){
		courseService.updateById(course);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("department:sys:delete")
    public R delete(@RequestBody Integer[] ids){
		courseService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
